use dataset_donors, clear

gen b = .
gen se = .

*******************************************************************************
* All states
*******************************************************************************

xi: reg ltotrep anywells i.year, a(zipcode) cl(zipcode)
replace b = _b[anywells] if _n == 1
replace se = _se[anywells] if _n == 1

xi: reg ltotdem anywells i.year, a(zipcode) cl(zipcode)
replace b = _b[anywells] if _n == 2
replace se = _se[anywells] if _n == 2

preserve

	gen index = _n
	drop if mi(b)
	collapse b se, by(index)

	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			yline(0, lcol(gray))
			xscale(range(0.75 2.25))
			xlab(1 "Republicans" 2 "Democrats")
			xtitle("Candidate party")
			ytitle("Effect of fracking")
			ylab(, angle(horiz) format(%20.02fc))
			title("All states")
			name(g3, replace)
			;

	#delimit cr

restore

*******************************************************************************
* High-fracking states
*******************************************************************************

xi: reg ltotrep anywells i.year if highf==1, a(zipcode) cl(zipcode)
replace b = _b[anywells] if _n == 1
replace se = _se[anywells] if _n == 1

xi: reg ltotdem anywells i.year if highf==1, a(zipcode) cl(zipcode)
replace b = _b[anywells] if _n == 2
replace se = _se[anywells] if _n == 2

preserve

	gen index = _n
	drop if mi(b)
	collapse b se, by(index)

	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			yline(0, lcol(gray))
			xscale(range(0.75 2.25))
			xlab(1 "Republicans" 2 "Democrats")
			xtitle("Candidate party")
			ytitle("Effect of fracking")
			ylab(, angle(horiz) format(%20.02fc))
			title("High-fracking states")
			name(g4, replace)
			;

	#delimit cr

restore

*******************************************************************************
* Combine plots 
*******************************************************************************

gr combine g3 g4, rows(1) title("(B) Contributions") ysize(2) xsize(4) ycommon
gr export "_output/figure4b.pdf", replace

*******************************************************************************
* End
*******************************************************************************
